<?php
/**
 * Created by PhpStorm.
 * User: qilin
 * Date: 2018/1/29
 * Time: 11:22
 */

namespace App\ServiceImpl;


use App\Model\Admin;
use App\Model\Certificate;
use App\Model\Vip;
use App\Model\WareHouse;
use App\Service\AdminService;

class AdminServiceImpl implements AdminService
{
    public function selectAdmin($adminData)
    {
        $adminData = Admin::where('admin_login_name',$adminData['admin_login_name'])
            ->where("admin_password",md5($adminData['admin_password']))
            ->first();
        return $adminData;
        // TODO: Implement selectAdmin() method.
    }
    public function getAdmin($adminId)
    {
        $adminData = Admin::find($adminId);
        return $adminData;
        // TODO: Implement getAdmin() method.
    }

    public function getAdminList(){
        $data = Admin::paginate(15);
        $data->count = $data->toArray()['total'];
        return $data;
    }

    public function addAdmin($admin)
    {
        $adminData = new Admin();
        $adminData->admin_nick_name = $admin['admin_nick_name'];
        $adminData->admin_login_name = $admin['admin_login_name'];
        $adminData->admin_password = md5($admin['admin_password']);
        $adminData->save();
        // TODO: Implement addAdmin() method.
    }
    public function deleteAdmin($id)
    {
        Admin::destroy($id);
        // TODO: Implement deleteAdmin() method.
    }
    public function getSystem()
    {
        $adminCount = Admin::count();
        $certificateCount = Certificate::count();
        $vipCount = Vip::count();
        $wareHouseCount = WareHouse::count();
        return [$adminCount,$certificateCount,$vipCount,$wareHouseCount];
        // TODO: Implement getSystem() method.
    }
    public function updateAdmin($admin)
    {
        Admin::where('admin_id',$admin['admin_id'])->update($admin);
        // TODO: Implement updateAdmin() method.
    }
}